package com.example.controller;

import com.example.feign.RemoteMessageFeignService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangzhenjun
 * @date 2023/10/31 14:40
 */
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/stock")
@RestController
public class StockController {

    private final RemoteMessageFeignService remoteMessageFeignService;

    @GetMapping(value = "/subtractStock")
    public String subtractStock(@RequestParam(value = "userId") Integer userId,@RequestParam(value = "productId") Integer productId, @RequestParam(value = "num") Integer num) {
        log.info("====>库存模块<========");
        if (productId < 1) {
            throw new RuntimeException("商品不存在，请重新请求！");
        }
        // 调用短信模块给用户发下单成功短信
        String messageResult = remoteMessageFeignService.sendMessage(userId);
        log.info("发送短信结果：{}", messageResult);
        return "扣减库存成功！";
    }
}
